//
//  NetworkAccessor.swift
//  驻外机组
//
//  Created by 苏伟 on 16/4/21.
//  Copyright © 2016年 com.csair. All rights reserved.
//

import SwiftyJSON


func GetItemsForCity(cityname:String){
    
    let req = NSMutableURLRequest(URL: NSURL(string: "http://10.242.8.38/ofc/api/city/?city=" + cityname)!)
    req.timeoutInterval = 6
    //req.addValue("9edac835f376cb64772fbcd764fcc94b", forHTTPHeaderField: "apikey")
    //响应对象
    var response:NSURLResponse?
    
    do{
        //发出请求
        let received:NSData? = try NSURLConnection.sendSynchronousRequest(req,
            returningResponse: &response)
        
        let json = JSON(data:received!)
        
        let cityItem = CityItem()
        
        //城市
        if let city = json["name"].string{
            //print("-------" + city)
            cityItem.city = city
        }else{
            print(json["name"].error)
        }
        
        SweetAlert().showAlert(cityItem.city)
        
    }catch let error as NSError{
        //打印错误消息
        print(error.code)
        print(error.description)
    }

}